Detailed Explanation of Python Basic Bracket of [] {}

  • 2021-12-12 08:56:25
  • OfStack

Catalog 1, braces in python () 2, braces in python [] 3, braces in python {} braces

Foreword:

Python There are three main data types: dictionary, list and tuple. They are respectively represented by curly braces, brackets and small brackets.

Such as:

Dictionary: dic={'a':12,'b':34} List: list=[1,2,3,4] Tuples: tup=(1,2,3,4)

python There are three kinds of brackets most commonly used in languages: brackets (), brackets [], and curly braces, also known as curly braces {}. Their functions are also different, and they are used to represent different python Basic built-in data type.

1. Parentheses in python ()

Representative tuple Tuple data type, tuple is an immutable sequence. The creation method is very simple, and most of the time it is enclosed in parentheses.


>>> tup = (1,2,3)
>>> tup
(1,2,3)
>>>
>>>()# Empty tuple 
()
>>>
>>>55,# A tuple of-values 
(55,)

2. Central brackets in python []

Representative list List data type, list is a mutable sequence. Its creation method is simple and special, like the following 1:


>>>list('python ')
[ 'p', 'y', 't', 'h', 'o', 'n']

3. python curly braces {} curly braces

Representative dict Dictionary data type, dictionary is composed of key pair value group. Colon Separate key and value, comma ' 'Separate groups.

The method created with curly braces is as follows:


>>> dic= {'jon':'boy','lili':'girl'}
>>> dic
{'lili':'girl','jon':'boy'}
>>>

Related articles: